package com.devMode.PrototypeMode;

/**
 * 原型模式
 * 要创建的对象类型，通过复制这个原型来创建新对象
 */
public class PrototypeMode {
    public static void main(String[] args) {
        Protorype protorype = new ConcreatePrototype("123");
        Protorype clone = protorype.myClone();
        System.out.println(clone.toString());
    }
}

abstract class Protorype{
    abstract Protorype myClone();
}

class ConcreatePrototype extends Protorype{

    private String field;

    public ConcreatePrototype(String field){
        this.field = field;
    }

    /**
     * 深克隆一个对象
     * @return
     */
    @Override
    Protorype myClone() {
        return new ConcreatePrototype(field);
    }

    @Override
    public String toString(){
        return field;
    }
}
